package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.factory.abstract.AbstractFactory
import com.kemai.designmode.factory.abstract.AppleAbstractFactory
import com.kemai.designmode.factory.abstract.BananaAbstractFactory
import com.kemai.designmode.factory.abstract.OrangeAbstractFactory
//抽象工厂模式调用(将某个对象的多种行为抽象成一个工厂)
class AbstractFactoryActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("邮寄苹果","邮寄香蕉","邮寄桔子")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("抽象工厂模式")
        setAdapterContent(studyContent,AbstractFactoryActivity@this,AbstractFactoryActivity@this)
    }

    override fun itemClick(position: Int) {
        var abstractFactory: AbstractFactory? = null
        when(position){
            0->{
                abstractFactory = AppleAbstractFactory()

            }
            1->{
                abstractFactory = BananaAbstractFactory()

            }
            2->{
                abstractFactory = OrangeAbstractFactory()

            }

        }
        abstractFactory?.getFruit()?.draw()
        abstractFactory?.getBag()?.pack()

    }

}